// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CategoryGroupDescription.cs" company="Akzente.IT">
//   (c) 2012 Akzente.IT
// </copyright>
// <summary>
//   A WPF GroupDescription to group items by their category name
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace AkzenteIT.DatabaseDocumentationTool.Util
{
    using System.ComponentModel;
    using System.Globalization;

    using AkzenteIT.DatabaseDocumentationTool.ViewModels.Base;

    /// <summary>
    /// A WPF GroupDescription to group items by their category name
    /// </summary>
    public class CategoryGroupDescription : GroupDescription
    {
        #region Public Methods and Operators

        /// <summary>
        /// The group name from item.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="level">
        /// The level.
        /// </param>
        /// <param name="culture">
        /// The culture.
        /// </param>
        /// <returns>
        /// The System.Object.
        /// </returns>
        public override object GroupNameFromItem(object item, int level, CultureInfo culture)
        {
            var node = item as NodeViewModel;

            var group = (node != null && node.Parent != null && node.Parent.IsCategory) ? node.Parent.Name : "All";

            if (!this.GroupNames.Contains(group))
            {
                this.GroupNames.Add(group);
            }

            return group;
        }

        /// <summary>
        /// The names match.
        /// </summary>
        /// <param name="groupName">
        /// The group name.
        /// </param>
        /// <param name="itemName">
        /// The item name.
        /// </param>
        /// <returns>
        /// The System.Boolean.
        /// </returns>
        public override bool NamesMatch(object groupName, object itemName)
        {
            var matches = base.NamesMatch(groupName, itemName);

            return matches;
        }

        #endregion
    }
}